package com.datang.pet.api.commentController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-15 19:07
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.CommentService;
import com.datang.pet.vo.AddLikeTwoCommentRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AddLikeTwoCommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/addLikeTwoComment")
    public Result addLikeTwoComment(@RequestBody AddLikeTwoCommentRequest addLikeTwoCommentRequest) throws Exception {

        if (!StringUtils.isNUll(addLikeTwoCommentRequest.getTwoCommentUserId())) {
            throw new Exception("二层评论作者id为空");
        }
        if (!StringUtils.isNUll(addLikeTwoCommentRequest.getTwoCommentId())) {
            throw new Exception("二层评论id为空");
        }
        if (!StringUtils.isNUll(addLikeTwoCommentRequest.getLikeUserId())) {
            throw new Exception("点赞人id为空");
        }
        if (!StringUtils.isNUll(addLikeTwoCommentRequest.getType())) {
            throw new Exception("点赞type为空");
        }

        try {
            addLikeTwoCommentRequest.setLikeUserId(MD5.decryptData(addLikeTwoCommentRequest.getLikeUserId()));
        } catch (Exception e) {
            throw new Exception("userId解密出错！");
        }




        commentService.addLikeTwoComment(addLikeTwoCommentRequest);
        return Result.ok("成功");
    }
}
